import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { ConsultPatial, formRef, Picture } from '@/types/consult'
import type { ConsultType, IllnessTime } from '@/enums/index'
export default defineStore(
  'consult',
  () => {
    // 所有的问诊信息会被收集到的对象中
    const consult = ref<ConsultPatial>({})
    // 1. 设置问诊的类型
    const setType = (v: ConsultType) => (consult.value.type = v)
    // 2. 记录问诊医院 三甲还是普通
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    // 3. 记录选择科室的id
    const setDepId = (id: string) => (consult.value.depId = id)
    // 4. 记录患者病情描述+周期+是否就诊+图片信息
    const setIllnessInfo = (obj: formRef) => {
      consult.value.illnessDesc = obj.illnessDesc
      consult.value.illnessTime = obj.illnessTime
      consult.value.consultFlag = obj.consultFlag
      consult.value.pictures = obj.pictures
    }
    // 5. 记录患者id
    const setPatientId = (id: string) => (consult.value.patientId = id)
    // 6. 清除信息
    const clear = () => (consult.value = {})
    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllnessInfo,
      setPatientId,
      clear
    }
  },
  { persist: true }
)
